<div class="row-content am-cf">
    <div class="row">
        <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
            <div class="widget am-cf">
                <form id="my-form" class="am-form tpl-form-line-form" enctype="multipart/form-data" method="post">
                    <div class="widget-body">
                        <fieldset>
                            <div class="widget-head am-cf">
                                <div class="widget-title am-fl">添加服务类目</div>
                            </div>
                            {if is_array($list)}
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">类目选择 </label>
                                <div class="am-u-sm-9 am-u-end">
                                    <select id="first" required 
                                           data-am-selected="{searchBox: 1 ,maxHeight: 300, btnSize: 'sm',placeholder:'请选择一级类目'}">
                                    </select>
									<select id="second" name="data[id]" required 
                                            data-am-selected="{searchBox: 1 ,maxHeight: 300 , btnSize: 'sm',placeholder:'请选择二级类目'}">
                                    </select>
                                </div>
                            </div>
							<div id='ca'>
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">资质名称 </label>
                                <div class="am-u-sm-9 am-u-end">
                                    <input id="ca_name" type="text" class="tpl-form-input" disabled >
                                </div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">资质图片 </label>
                                <div class="am-u-sm-9 am-u-end">
                                    <div class="am-form-file">
                                        <button type="button"
                                                class="upload-file am-btn am-btn-secondary am-radius">
                                            <i class="am-icon-cloud-upload"></i> 选择图片
                                        </button>
                                        <div class="uploader-list am-cf">
                                        </div>
                                    </div>
                                    <div class="help-block am-margin-top-sm">
                                        <small>该类目必须提供资质认证图片</small>
                                    </div>
                                </div>
                            </div>
							</div>
							<!-- 事件功能 -->
							<div class="am-modal am-modal-loading am-modal-no-btn" tabindex="-1" id="my-modal-loading"></div>
                            <div class="am-form-group">
                                <div class="am-u-sm-9 am-u-sm-push-3 am-margin-top-lg">
                                    <button type="submit" class="j-submit am-btn am-btn-secondary">提交
                                    </button>
                                </div>
                            </div>
                        {else /}
                            <div class="am-form-group">
                                <div class="tips am-margin-bottom-sm am-u-sm-12">
                                    <div class="pre-error">
                                        <p>{$list}</p>
                                    </div>
                                </div>
                            </div>
                        {/if}
                        </fieldset>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<!-- 图片文件列表模板 -->
{include file="layout/_template/tpl_file_item_url" /}
<!-- 文件库弹窗 -->
{include file="layout/_template/file_library" /}

<script>
    $(function () {
		$(document).ready(function(){$("#ca").hide();});
        // 选择图片
        $('.upload-file').selectImages({
            name: 'data[certicates]'
        });
		var data = <?= json_encode($list)?>;
		var first = '<option value=""></option>';
		for(var i=0;i<data.length;i++){
            first += '<option value="'+i+'" >'+data[i].name+'</option>';
        }
        $('#first').empty();
        $('#first').append(first);
		//监听一级类目
		$('#first').change(() => {
				var first_value = $('#first').val();
				var children = data[first_value].children;
				var second = '<option value=""></option>';
				for(var i=0;i<children.length;i++){
					second += '<option value="'+first_value+'.'+i+'" >'+children[i].name+'</option>';
				}
				$('#second').empty();
				$('#second').append(second);
		});
		//监听二级类目
		$('#second').change(() => {
				var value = $('#second').val();
				if(value!==''){
					value = value.split('.');//拆分数组
					
					if(data[value[0]].children[value[1]].sensitive_type==1){
						$(document).ready(function(){$("#ca").show();});
						$("#ca_name").val(data[value[0]].children[value[1]].qualify.exter_list[0].inner_list[0].name);
					}else{
						$(document).ready(function(){$("#ca").hide();});
					}
				}
		});

        $('#my-form').formPost();

    });
</script>
